//
//  MNDPomeloCircleTableViewController.m
//  minidai
//
//  Created by 谭谭伟 on 17/5/24.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDPomeloCircleTableViewController.h"
#import "MNDMessageModel.h"
#import "MNDMunityLevelModel.h"
#import "MNDMyIntegralViewController.h"
#import "MNDSignInAlertViewController.h"
#import "MNDWebViewController.h"
#import "MNDLoginUserModel.h"
#import "RSAUtil.h"
#import "SYRefreshControl.h"
#import "MNDBBSViewController.h"
#import "UIImage+JKColor.h"
#import "MNDTPQHistoryViewController.h"
#import "MNDCarAssessHistoryViewController.h"

typedef NS_ENUM(NSInteger, BtnType) {
    BtnTypeCommunity = 100, //社区
    BtnTypeIntroduce,       //平台介绍
    BtnTypeCustomerGuide,   //用户指南
    BtnTypeCustomerService  //在线客服
};
@interface MNDPomeloCircleTableViewController ()
/* 用户社区信息模型 */
@property (strong, nonatomic) MNDMunityLevelModel *munityLevelModel;
/* 最新消息 */
@property (strong, nonatomic) MNDMessageModel *bestNewMessageModel;
/* 每日话题 */
@property (strong, nonatomic) MNDMessageModel *everyDayTopicModel;
//每日话题
@property (weak, nonatomic) IBOutlet UILabel *everyDayTopLabel;
@property (weak, nonatomic) IBOutlet UILabel *releaseTimeLabel;
//最新公告
@property (weak, nonatomic) IBOutlet UILabel *activityLabel;
@property (weak, nonatomic) IBOutlet UILabel *activityTimeLabel;
//用户头像
@property (weak, nonatomic) IBOutlet UIButton *iconButton;
//昵称
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
//等级
@property (weak, nonatomic) IBOutlet UIButton *userLevelButton;
//用户积分
@property (weak, nonatomic) IBOutlet UILabel *userIntergelLabel;
//查看我的积分
@property (weak, nonatomic) IBOutlet UIButton *myIntergelButton;
@property (weak, nonatomic) IBOutlet UIButton *signInButton;

@property (weak, nonatomic) IBOutlet UIButton *loginButton;
@property (weak, nonatomic) IBOutlet UIView *tipsView;
@property (weak, nonatomic) IBOutlet UIButton *loginMaskButton;

//蜜柚社区
@property (weak, nonatomic) IBOutlet UIStackView *communityView;
//平台介绍
@property (weak, nonatomic) IBOutlet UIStackView *platFormIntroduceView;
//新手指南
@property (weak, nonatomic) IBOutlet UIStackView *guideView;
//在线客服
@property (weak, nonatomic) IBOutlet UIStackView *customerServiceView;
//违章查询
@property (weak, nonatomic) IBOutlet UIStackView *trafficPeccancyView;
//车辆估值
@property (weak, nonatomic) IBOutlet UIStackView *carAssessView;

@end

@implementation MNDPomeloCircleTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (@available(iOS 11, *)) {
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //安全退出先清除原先用户的数组
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupWithoutView) name:@"clearPomeCircleData" object:nil];
    if ([MNDLoginUserModel isUserLogin]) {
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
        //用户名称
        self.userNameLabel.text = [NSString stringWithFormat:@"您好,%@", user.user_name];
        //已经登录图
            [self setupLoginView];
        }else {
            [self setupWithoutView];
        }
    
    [self loadData];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [self setStatusBarBackgroundColor:[UIColor whiteColor]];
    
    //导航条背景透明
    UIImage *image = [UIImage jk_imageWithColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.shadowImage = image;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.shadowImage = [UIImage jk_imageWithColor:[UIColor colorWithHex:0xF1F1F1]];
    [self setStatusBarBackgroundColor:[UIColor clearColor]];
}

//设置状态栏颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
    
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    NSLog(@"statusBar.backgroundColor--->%@",statusBar.backgroundColor);
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

//已经登录图
- (void)setupLoginView {
    self.myIntergelButton.userInteractionEnabled = YES;
    [self.myIntergelButton setTitleColor:[UIColor colorWithRed:255/255.0 green:110/255.0 blue:65/255.0 alpha:1.0] forState:UIControlStateNormal];
    self.signInButton.userInteractionEnabled = YES;
    self.userNameLabel.hidden = NO;
    self.userLevelButton.hidden = NO;
    self.loginButton.hidden = YES;
//    self.loginMaskButton.hidden = YES;
    
}

//未登录图
- (void)setupWithoutView {
    self.myIntergelButton.userInteractionEnabled = NO;
    [self.myIntergelButton setTitleColor:[UIColor colorWithRed:142/255.0 green:142/255.0 blue:142/255.0 alpha:1.0] forState:UIControlStateNormal];
//    self.signInButton.userInteractionEnabled = NO;
    self.userIntergelLabel.textColor = [UIColor colorWithRed:142/255.0 green:142/255.0 blue:142/255.0 alpha:1.0];
    self.userNameLabel.hidden = YES;
    self.userLevelButton.hidden = YES;
    self.loginButton.hidden = NO;
//    self.loginMaskButton.hidden = NO;
    [self.iconButton setImage:[UIImage imageNamed:@"user_center_avatar_color"] forState:UIControlStateNormal];
}

#pragma mark -加载数据
- (void)loadData {
    if ([MNDLoginUserModel isUserLogin]) {
        //积分及头像获取
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];

        NSDictionary *params = [MNDSign signedParamWithDict:@{@"user_code": user.user_code}];
        WeakSelf(self);
        [APIManager sendRequestWithPath:API_POMELCIRCLE_LEVEL parameters:params method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
            if(responseModel.status == ResponseSuccess){
                NSLog(@"%@",responseModel.data);
                NSDictionary *responseDict = [responseModel yy_modelToJSONObject];
                NSDictionary *dataDict = [responseDict objectForKey:@"data"];
                self.munityLevelModel = [MNDMunityLevelModel yy_modelWithJSON:dataDict];
                [weakself configMyInfoContent];
                
            } else {
                [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
            }
        } onFailure:^(NSError *error) {
            [NetworkProgressHUD showHudNetworkError:error];
        }];
    }else {
        [self.signInButton setTitle:@"签到送积分" forState:UIControlStateNormal];
        self.userIntergelLabel.text = @"累积获得0积分";
    }
    WeakSelf(self);
    //最新公告
    NSDictionary *bestNewMessageParam = [MNDSign signedParamWithDict:@{@"pagesize":@"1",@"plate_id":@"1"}];
    [APIManager sendRequestWithPath:API_NOTICE_LIST parameters:bestNewMessageParam method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            NSDictionary *responseDict = [responseModel yy_modelToJSONObject];
            NSArray *responseArr = [responseDict objectForKey:@"data"];
            NSArray *messageArr = [NSArray yy_modelArrayWithClass:[MNDMessageModel class] json:responseArr];
            weakself.bestNewMessageModel = messageArr[0];
            weakself.activityLabel.text = weakself.bestNewMessageModel.title;
            weakself.activityTimeLabel.text = weakself.bestNewMessageModel.forum_releasetime;
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
    
    //每日话题
    NSDictionary *everyDayParam = [MNDSign signedParamWithDict:@{@"pagesize":@"1",@"plate_id":@"6"}];
    [APIManager sendRequestWithPath:API_NOTICE_LIST parameters:everyDayParam method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            NSDictionary *responseDict = [responseModel yy_modelToJSONObject];
            NSArray *responseArr = [responseDict objectForKey:@"data"];
            NSArray *messageArr = [NSArray yy_modelArrayWithClass:[MNDMessageModel class] json:responseArr];
            weakself.everyDayTopicModel = messageArr[0];
        }else {
            [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
        }
        weakself.everyDayTopLabel.text = weakself.everyDayTopicModel.title;
        weakself.releaseTimeLabel.text = weakself.everyDayTopicModel.forum_releasetime;
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
    [SYRefreshControl configAfterLoading:self.tableView hasData:YES];
}

- (void)setupUI {
    self.iconButton.layer.cornerRadius = self.iconButton.bounds.size.height*0.5;
    self.iconButton.clipsToBounds = YES;
    self.userLevelButton.layer.cornerRadius = self.userLevelButton.bounds.size.height*0.5;
    self.userLevelButton.clipsToBounds = YES;
    //刷新数据
    [SYRefreshControl configGifMJRefresh:self.tableView refreshType:MJRefreshSupportRefresh beginRefresh:NO timeLabelHidden:YES stateLabelHidden:YES refreshBlock:^{
        [self loadData];
    } loadMoreBlock:nil];
    
    //添加点击事件
    [self.communityView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithCommunity:)]];
    [self.platFormIntroduceView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithPlatForm:)]];
    [self.guideView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithGuide:)]];
    [self.customerServiceView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithCustomeService:)]];
    [self.trafficPeccancyView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithTraffic:)]];
    [self.carAssessView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMidWithAssess:)]];

}

#pragma mark -Action

- (IBAction)callPhoneAction:(UIButton *)sender {
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",kServicePhoneNumber]]];
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", kServicePhoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}


- (void)configMyInfoContent {
    //用户头像
    UIImage *iconImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.munityLevelModel.user_photo]] scale:0.5];
    [self.iconButton setImage:iconImg forState:UIControlStateNormal];
 
    //用户名称
    self.userNameLabel.text = [NSString stringWithFormat:@"您好,%@",self.munityLevelModel.user_name];
    //用户社区等级
    [self.userLevelButton setTitle:[NSString stringWithFormat:@"Lv.%@",self.munityLevelModel.grade_id]forState:UIControlStateNormal];
    //用户积分
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"累积获得%@积分",self.munityLevelModel.user_integral]];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:255/255.0 green:110/255.0 blue:65/255.0 alpha:1.0] range:NSMakeRange(4, str.length-4)];
    if ([self.munityLevelModel.is_sign isEqualToString:@"1"]) {
        [self.signInButton setTitle:@"签到成功,明天再来" forState:UIControlStateNormal];
    }else {
        [self.signInButton setTitle:@"签到送积分" forState:UIControlStateNormal];
    }
    self.userIntergelLabel.attributedText = str;

}
//我的积分
- (IBAction)myIntergalAction:(UIButton *)sender {
    MNDMyIntegralViewController *myIntegralViewController = [[MNDMyIntegralViewController alloc]init];
    myIntegralViewController.myTotalScore = self.munityLevelModel.user_enable_integral;
    [self.navigationController pushViewController:myIntegralViewController animated:YES];
}

//签到
- (IBAction)siginAction:(UIButton *)sender {
    if ([MNDLoginUserModel isUserLogin]) {
        [NetworkProgressHUD showHud];
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];

        NSDictionary *params = [MNDSign signedParamWithDict:@{@"user_code": user.user_code}];
        
        WeakSelf(self);
        [APIManager sendRequestWithPath:API_BBS_PLACE parameters:params method:kXMHTTPMethodGET onSuccess:^(ResponseModel *responseModel) {
            if (responseModel.status == ResponseSuccess) {
                [NetworkProgressHUD hideHud];
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                __weak MNDSignInAlertViewController *alertVC = [storyboard instantiateViewControllerWithIdentifier:@"MNDSignInAlertViewController"];
                __weak UIView *springView = alertVC.view;
                [KeyWindow addSubview:springView];
                [weakself addChildViewController:alertVC];
                //    __weak typeof(self) weakSelf = self;
                [alertVC.closeButton bk_addEventHandler:^(id sender) {
                    [UIView animateWithDuration:0.5 animations:^{
                        alertVC.alertView.frame = CGRectMake(alertVC.alertView.frame.origin.x, kScreenHeight, alertVC.alertView.frame.size.width, alertVC.alertView.frame.size.height);
                    } completion:^(BOOL finished) {
                        [springView removeFromSuperview];
                        [alertVC removeFromParentViewController];
                    }];
                    
                } forControlEvents:UIControlEventTouchUpInside];
                [alertVC.checkMyScordButton bk_addEventHandler:^(id sender) {
                    [springView removeFromSuperview];
                    [alertVC removeFromParentViewController];
                    //查看积分
                    MNDMyIntegralViewController *myIntegralViewController = [[MNDMyIntegralViewController alloc]init];
                    myIntegralViewController.myTotalScore = self.munityLevelModel.user_enable_integral;
                    myIntegralViewController.hidesBottomBarWhenPushed = YES;
                    [weakself.navigationController pushViewController:myIntegralViewController animated:YES];
                } forControlEvents:UIControlEventTouchUpInside];
                [alertVC.checkExchangeRegularButton bk_addEventHandler:^(id sender) {
                    [springView removeFromSuperview];
                    [alertVC removeFromParentViewController];
                    [weakself checkIntegralRegulation];
                } forControlEvents:UIControlEventTouchUpInside];
                [weakself loadData];
            }else {
                [NetworkProgressHUD hideHud];
                [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
            }
        } onFailure:^(NSError *error) {
            [NetworkProgressHUD showHudNetworkError:error];
        }];
    }else {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
        UINavigationController *naviVC = [storyboard instantiateInitialViewController];
        
        [self presentViewController:naviVC animated:YES completion:^{
            
        }];
    }
}

- (void)checkIntegralRegulation {
    MNDWebViewController *webVC = [[MNDWebViewController alloc]init];
    webVC.naviBarHidden = YES;
    webVC.webViewUrl = [NSString stringWithFormat:@"%@%@", WebBaseURL, kScoreRegular];
    webVC.isFromIntegral = YES;
    webVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webVC animated:YES];
}

- (IBAction)loginAction:(UIButton *)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    UINavigationController *naviVC = [storyboard instantiateInitialViewController];
    
    [self presentViewController:naviVC animated:YES completion:^{
        
    }];
}
- (IBAction)goLoginAction:(id)sender {
    if ([MNDLoginUserModel isUserLogin]) {
        MNDWebViewController *mndWebViewController = [[MNDWebViewController alloc]init];
        mndWebViewController.hidesBottomBarWhenPushed = YES;
        
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
        mndWebViewController.circleEncodeUserCode = [self rsaEncode: user.user_code];
        mndWebViewController.circleEncodeUserName = [self rsaEncode: user.user_name];
        mndWebViewController.title = @"蜜柚社区";
        mndWebViewController.circleEncodeUserId = [self rsaEncode: user.user_id];
        mndWebViewController.webViewUrl = kCommunityPersonageURLStr;
        [self.navigationController pushViewController:mndWebViewController animated:YES];

    }else {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
        UINavigationController *naviVC = [storyboard instantiateInitialViewController];
        
        [self presentViewController:naviVC animated:YES completion:^{
            
        }];

    }
}
- (IBAction)iconButtonAction:(UIButton *)sender {
    
}

//点击头像
- (IBAction)iconAction:(UIButton *)sender {
    
    if ([MNDLoginUserModel isUserLogin]) {
        MNDWebViewController *mndWebViewController = [[MNDWebViewController alloc]init];
        mndWebViewController.hidesBottomBarWhenPushed = YES;
        
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
        mndWebViewController.circleEncodeUserCode = [self rsaEncode: user.user_code];
        mndWebViewController.circleEncodeUserName = [self rsaEncode: user.user_name];
        mndWebViewController.title = @"蜜柚社区";
        mndWebViewController.circleEncodeUserId = [self rsaEncode: user.user_id];
        mndWebViewController.webViewUrl = kCommunityPersonageURLStr;
        [self.navigationController pushViewController:mndWebViewController animated:YES];
    } else {
    
    }
}

//积分规则
- (IBAction)exchageReguraAction:(UIButton *)sender {
    
    MNDWebViewController *webVC = [[MNDWebViewController alloc]init];
    webVC.naviBarHidden = YES;
    webVC.webViewUrl = [NSString stringWithFormat:@"%@%@", WebBaseURL, kScoreRegular];
    webVC.isFromIntegral = YES;
    webVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webVC animated:YES];
}

//蜜柚社区
- (void)clickMidWithCommunity:(UITapGestureRecognizer *)gesture {
    MNDWebViewController *mndWebViewController = [[MNDWebViewController alloc]init];
    mndWebViewController.hidesBottomBarWhenPushed = YES;
    if ([MNDLoginUserModel isUserLogin]) {
        MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
        mndWebViewController.circleEncodeUserCode = [self rsaEncode: user.user_code];
        mndWebViewController.circleEncodeUserName = [self rsaEncode: user.user_name];
        mndWebViewController.title = @"蜜柚社区";
        mndWebViewController.circleEncodeUserId = [self rsaEncode: user.user_id];
    }
    mndWebViewController.loadType = LoadTypeLink;
    mndWebViewController.webViewUrl = kCommunityURLStr;
    [self.navigationController pushViewController:mndWebViewController animated:YES];
}

//平台介绍--5.1版本后换成运营报告
- (void)clickMidWithPlatForm:(UITapGestureRecognizer *)gesture {
    
    MNDWebViewController *webVC = [[MNDWebViewController alloc]init];
    webVC.webViewUrl = kReports;
    webVC.title = @"运营报告";
    webVC.isCircleReport = YES;
    webVC.hidesBottomBarWhenPushed = YES;
    //        webVC.naviBarHidden = YES;
    [self.navigationController pushViewController:webVC animated:YES];
}

//新手指南
- (void)clickMidWithGuide:(UITapGestureRecognizer *)gesture {
    MNDWebViewController *mndWebViewController = [[MNDWebViewController alloc]init];
    mndWebViewController.hidesBottomBarWhenPushed = YES;
    mndWebViewController.webViewUrl = [NSString stringWithFormat:@"%@%@", WebBaseURL, kUserGuide];
    mndWebViewController.title = @"用户指南";
    mndWebViewController.naviBarHidden = YES;
    [self.navigationController pushViewController:mndWebViewController animated:YES];
}

//在线客服
- (void)clickMidWithCustomeService:(UITapGestureRecognizer *)gesture {
    MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
    MNDBBSViewController *bbsVC = [[MNDBBSViewController alloc]init];
    
    NSString *str = [NSString stringWithFormat:@"%@?user_id=%@&user_name=%@",kCustomerServiceURLStr, user.user_id, user.user_name];
    bbsVC.url = str;
    bbsVC.isCustomService = YES;
    bbsVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:bbsVC animated:YES];
}

//违章查询
- (void)clickMidWithTraffic:(UITapGestureRecognizer *)gesture {
    MNDTPQHistoryViewController *trafficVC = [UIStoryboard viewControllerWithIdentifier:@"MNDTPQHistoryViewController"];
    [self.navigationController pushViewController:trafficVC animated:YES];
}

//车辆估值
- (void)clickMidWithAssess:(UITapGestureRecognizer *)gesture {
    MNDCarAssessHistoryViewController *assessVC = [UIStoryboard viewControllerWithIdentifier:@"MNDCarAssessHistoryViewController"];
    [self.navigationController pushViewController:assessVC animated:YES];
}

////点击中间4个按钮
//- (IBAction)clickMidAction:(UIButton *)sender {
//    MNDWebViewController *mndWebViewController = [[MNDWebViewController alloc]init];
//    mndWebViewController.hidesBottomBarWhenPushed = YES;
//    
//    switch (sender.tag) {
//        case BtnTypeCommunity: //社区
//        {
//            if ([MNDLoginUserModel isUserLogin]) {
//                MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
//                mndWebViewController.circleEncodeUserCode = [self rsaEncode: user.user_code];
//                mndWebViewController.circleEncodeUserName = [self rsaEncode: user.user_name];
//                mndWebViewController.title = @"蜜柚社区";
//                mndWebViewController.circleEncodeUserId = [self rsaEncode: user.user_id];
//            }
//            mndWebViewController.loadType = LoadTypeLink;
//            mndWebViewController.webViewUrl = kCommunityURLStr;
//            [self.navigationController pushViewController:mndWebViewController animated:YES];
//        }
//            break;
//        case BtnTypeIntroduce: {//平台介绍
//            mndWebViewController.webViewUrl = [NSString stringWithFormat:@"%@",kComPanyIntroduce];
//            mndWebViewController.title = @"平台介绍";
//            mndWebViewController.naviBarHidden = YES;
//            [self.navigationController pushViewController:mndWebViewController animated:YES];
//        }
//            break;
//        case BtnTypeCustomerGuide: //用户指南
//        {
//            mndWebViewController.webViewUrl = [NSString stringWithFormat:@"%@%@", WebBaseURL, kUserGuide];
//            mndWebViewController.title = @"用户指南";
//            mndWebViewController.naviBarHidden = YES;
//            [self.navigationController pushViewController:mndWebViewController animated:YES];
//        }
//            break;
//            
//        case BtnTypeCustomerService: //在线客服
//        {
//            MNDLoginUserModel *user = [MNDLoginUserModel currentLoginUser];
//            MNDBBSViewController *bbsVC = [[MNDBBSViewController alloc]init];
//            
//            NSString *str = [NSString stringWithFormat:@"%@?user_id=%@&user_name=%@",kCustomerServiceURLStr, user.user_id, user.user_name];
//            bbsVC.url = str;
//            bbsVC.isCustomService = YES;
//            bbsVC.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:bbsVC animated:YES];
//        }
//            break;
//            
//        default:
//            break;
//    }
//}

- (NSString *)rsaEncode:(NSString *)rsaStr {
    NSString *encryText = [RSAUtil encryptString:[NSString stringWithFormat:@"%@", rsaStr] publicKey:RSA_PUBLIC_KEY];
    NSString *unreserved = @"";
    NSMutableCharacterSet *allowed = [NSMutableCharacterSet alphanumericCharacterSet];
    [allowed addCharactersInString:unreserved];
    
    NSString *encodeEncryText = [encryText stringByAddingPercentEncodingWithAllowedCharacters:allowed];

    return encodeEncryText;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 2) {
        return 2;
    }else {
        return 1;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 2) {
        MNDBBSViewController *webVC = [[MNDBBSViewController alloc]init];
        if (indexPath.row == 0) {//最新公告
            webVC.url = [NSString stringWithFormat:@"%@%@",kNoticeBBSURL,_everyDayTopicModel.forum_code];
            webVC.title = @"蜜柚社区";
            webVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webVC animated:YES];
        }else {//每日话题

            webVC.url = [NSString stringWithFormat:@"%@%@",kNoticeBBSURL,_bestNewMessageModel.forum_code];
            webVC.title = @"蜜柚社区";
            webVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webVC animated:YES];


        }

    }
    }
@end
